package bishi.likou_1_30;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @auther Tang Xiaozun
 * @date 2022/1/30
 */
public class two {
    public static void main(String[] args) {
        System.out.println(new two().maxScoreIndices(new int[]{0,0,1,0}));
    }
    public List<Integer> maxScoreIndices(int[] nums) {
        int[] left = new int[nums.length+2];int leftN = 0;
        int[] right = new int[nums.length+2];int rightN = 0;
        for(int i=0;i<=nums.length;i++){
            if(i<nums.length&&nums[i]==0){
                leftN++;
            }
            left[i] = leftN;
            if(i>0&&nums[nums.length-i]==1){
                rightN++;
            }
            right[nums.length-i] = rightN;
        }
        List<Integer> res = new ArrayList<>();
        int max = 0;
        for(int i=0;i<nums.length+1;i++){
            int sum = right[i]+(i>0?left[i-1]:0);
            if(sum==max){
                res.add(i);
            }else if(sum>max){
                max = sum;
                res = new ArrayList<>();
                res.add(i);
            }
        }
        return res;

    }
}
